/**
 * Created by jackliu on 15/12/6.
 */
import SJGPage = require('./../kernel/cont/SJGPage');
import ObjManager = require('./../kernel/cont/ObjManager');
import TextObj = require('./../kernel/obj/TextObj');
import TextExtObj = require('./../kernel/obj/TextExtObj');
import ParaContour = require('./../common/graph/ParaContour');
import SJGReplaceGroup = require('./../kernel/replace/SJGReplaceGroup');
import SJGReplaceItemText = require('./../kernel/replace/SJGReplaceItemText');
import SJGTypeSetItemBase = require('./SJGTypeSetItemBase');
import GCJ_CLASS_TYPE= require('./../common/GCJ_CLASS_TYPE');
var async  = require( 'async'); // 同步控制
export = SJGTypeSetCommentGroup;

class SJGTypeSetCommentGroup extends  SJGTypeSetItemBase{

    // 标题组 排版核心 与其它类型组的处理方式不同
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public do(p:SJGPage,group: SJGReplaceGroup ,callback) {
        var objMgr:ObjManager = p.getGlobalData().objManager();
        var THIS = this;
        this.page = p;

        // 备注 位置不变 更新内容
        for(var i in group.value){
            var comment:SJGReplaceItemText =<SJGReplaceItemText> group.value[i];
            var obj = objMgr.getObject(comment.id);
            if(!obj)    continue;

            if(obj.ct == GCJ_CLASS_TYPE.CLASS_TYPE_TextObj){
                var textObj:TextObj = <TextObj>obj;
                // 旧文字TextObj
                // 设置文字内容和轮廓
                textObj.te = comment.value;
                textObj.pc = ParaContour.fromFontServerData(comment.value, JSON.parse(comment.originContour));
                // 调整文字的宽度
                textObj.refresh();
                //textObj.refreshToOneLineAndFixWidth();// 使得总结在同一行，且固定宽度
            }else if(obj.ct == GCJ_CLASS_TYPE.CLASS_TYPE_TextExtObj){
                // 处理新文字TextExtObj 20160623
                var textExtObj:TextExtObj = <TextExtObj>obj;
                if(textExtObj){
                    // 设置文字内容和轮廓
                    textExtObj.te = comment.value;
                    textExtObj.pc = ParaContour.fromFontServerData(comment.value, JSON.parse(comment.originContour));
                    // 调整文字的宽度
                    textExtObj.refresh();
                    //textExtObj.refreshToOneLineAndFixWidth();// 使得总结在同一行，且固定宽度
                }
            }
        }



        // 回调
        callback(null ,null);
    }
}